<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Azure
 * Date: 10/07/13
 * Time: 2:36
 * To change this template use File | Settings | File Templates.
 */

function getCategorias($idPadre = -1){
    global $db;

    $rtrn = array();

    if ($idPadre == -1 )
        $sSql = "select id from categorias where idPadre <> 0";
    else
        $sSql = "select id from categorias where idPadre = 0";

    $res = $db->execSql($sSql);
    while ($row = mysqli_fetch_assoc($res)) {
        $rtrn[] = new \categoria\categoria($row["id"]);
    }

    return $rtrn;
}

function getCategoriasHijas($idPadre=0){
    global $db;

    $rtrn = array();

    $sSql = "select id from categorias where idPadre = ".$idPadre;

    $res = $db->execSql($sSql);
    while ($row = mysqli_fetch_assoc($res)) {
        $rtrn[] = new \categoria\categoria($row["id"]);
    }

    return $rtrn;
}

function getImagesFromCategory($iIdCat = 0){
    global $db;

    $rtrn = array();

    $sSql = "select id from imagenes where idcategoria = ".$iIdCat;
    $res = $db->execSql($sSql);
    while ($row = mysqli_fetch_assoc($res)) {
        $rtrn[] = new \imagen\imagenes($row["id"]);
    }

    return $rtrn;

}

function checkLogin($user,$pass){
    global $db;

    $rtrn = false;

    $sMd5Pass = strtoupper(md5($pass));

    $sSql = "select * from usuarios where usuario = '".strtolower($user)."' and password = '".$sMd5Pass."'";

    $res = $db->execSql($sSql);

    if ($res){
        while ($row = mysqli_fetch_assoc($res)) {
            $rtrn = true;
        }
    }

    return $rtrn;

}

?>